package com.example.demo.controller;

import com.example.demo.service.Assistant;
import com.example.demo.service.StreamChatAssistant;
import dev.langchain4j.data.message.SystemMessage;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.chat.StreamingChatLanguageModel;
import dev.langchain4j.service.TokenStream;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/chat/api")
public class ChatController {

    final ChatLanguageModel chatLanguageModel;

    @GetMapping("/low/chat")
    public Object lowChat(@RequestParam(value = "message")String message){
        String text=chatLanguageModel.chat(List.of(SystemMessage.systemMessage("假如你是特朗普，接下来请以特朗普的语气和我对话"),
                UserMessage.userMessage(message))).aiMessage().text();
        return text;
//        String text=chatLanguageModel.chat(UserMessage.from(message)).aiMessage().text();
//        return text;
    }

    final Assistant assistant;

    @GetMapping("/high/chat")
    public String highChat(@RequestParam(value = "message")String message){
        return assistant.chat(message);
    }


    final StreamChatAssistant streamChatAssistant;

    @GetMapping("/high/chat/stream")
    public Flux<String> streamingChat(@RequestParam(value = "message")String message){
        return streamChatAssistant.chat(message);
    }


}
